package org.liu.simpleTank;

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Timer;
import java.util.TimerTask;

public class Main extends Applet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3095198728375332933L;
	private Game game;
	
	@Override
	public void init() {
		this.resize(CONSTS.SW, CONSTS.SH);
		game = new Game(this);
		game.init();
	}
	
	@Override
	public void start() {
		game.start();
		this.repaint();
		Timer t = new Timer(true);
		t.schedule(this.new updateTask(), 0, 16);
	}
	
	@Override
	public void stop() {
		game.stop();
	}
	
	@Override
	public void update(Graphics g) {
		paint(g);
	}
	
	@Override
	public void paint(Graphics g) {
		synchronized (game.getFrame()) {
			g.drawImage(game.getFrame(), 0, 0, null);
		}
	}
	
	class updateTask extends TimerTask {
		@Override
		public void run() {
			Main.this.repaint();
			synchronized (game.getFrame()) {
				game.update();
			}
		}
	}
}
